package com.yb.guigu.pick.security.handler;

import com.yb.guigu.pick.core.bean.GuiguResult;
import com.yb.guigu.pick.core.constant.GuiguStatus;
import org.springframework.http.MediaType;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/5/31 13:44
 * FileName: GuiguPickAccessDeniedHandler
 * Description:
 */
public class GuiguPickAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
        response.getWriter().write(GuiguResult.error(GuiguStatus.HttpStatus.FORBIDDEN).toJSON());
    }
}
